package com.itcast.reflect;

import com.itcast.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {
        // 1.获取 class 对象
        Class<Person> personClass = Person.class;

        // 2.获取构造方法
        Constructor<?>[] constructors = personClass.getConstructors();
        for (Constructor c : constructors) {
            System.out.println(c);
        }
        System.out.println("--------");
        Constructor<Person> constructor = personClass.getConstructor(String.class, int.class);
        System.out.println(constructor);

        // 创建对象
        Person person = constructor.newInstance("张三", 20);
        System.out.println(person);


    }
}
